package com.xbongbong.admin.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.admin.domain.entity.RaidersCorpEntity;
import com.xbongbong.admin.domain.entity.RaidersEntity;
import com.xbongbong.admin.help.RaidersHelp;
import com.xbongbong.admin.model.RaidersCorpModel;
import com.xbongbong.admin.pojo.PointPojo;
import com.xbongbong.admin.pojo.PointUrlBasePojo;
import com.xbongbong.admin.pojo.StepInfoPojo;
import com.xbongbong.admin.pojo.dto.RaidersDetailDTO;
import com.xbongbong.admin.pojo.dto.RaidersListDTO;
import com.xbongbong.admin.pojo.dto.RaidersOperationDetailDTO;
import com.xbongbong.admin.pojo.vo.RaidersDetailVO;
import com.xbongbong.admin.pojo.vo.RaidersListVO;
import com.xbongbong.admin.pojo.vo.RaidersOperationDetailVO;
import com.xbongbong.admin.pojo.vo.RaidersVO;
import com.xbongbong.admin.service.RaidersService;
import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.paas.enums.DelEnum;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.BeanUtil;
import com.xbongbong.paas.toolbox.util.CollectionsUtil;
import com.xbongbong.paas.toolbox.util.DateUtil;
import com.xbongbong.paas.toolbox.util.JsonHelperUtil;
import com.xbongbong.pro.constant.CommonConstant;
import com.xbongbong.pro.constant.RaidersConstant;
import com.xbongbong.pro.enums.errorcodes.RaidersErrorCodeEnum;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.enums.permission.enums.ProPermissionAliasEnum;
import com.xbongbong.pro.enums.raiders.enums.RaidersGroupRecommendEnum;
import com.xbongbong.pro.enums.raiders.enums.RaidersLockEnum;
import com.xbongbong.pro.enums.raiders.enums.RaidersPointChildEnum;
import com.xbongbong.pro.enums.raiders.enums.RaidersRangeEnum;
import com.xbongbong.pro.enums.raiders.enums.RaidersStepEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

/**
 * @author zcp
 * @version v1.0
 * @date 19/9/23 023 20:45
 * @update 19/9/23 023 20:45
 * @since v1.0
 */
@Service("raidersService")
public class RaidersServiceImpl implements RaidersService {

    private static final Logger LOG = LoggerFactory.getLogger(RaidersServiceImpl.class);

    @Resource
    private RaidersHelp raidersHelp;
    @Resource
    private RaidersCorpModel raidersCorpModel;

    @Override
    public RaidersListVO list(RaidersListDTO raidersListDTO) throws XbbException {
        RaidersListVO raidersListVo = new RaidersListVO();
        try {
            String corpid = raidersListDTO.getCorpid();
            Long groupId = raidersListDTO.getGroupId();
            /*
              如果是私有推荐分组，获取的是私有分组下面的所有私有攻略（可能有的攻略并没有推荐给该公司，后面查询RaidersCorpEntity时，会限制corpid，自动排除其他不适本公司的私有攻略）
             */
            List<RaidersEntity> list = raidersHelp.getRaidersList4Filter(corpid, groupId, raidersListDTO.getLoginUser());
            if (list.size() == 0) {
                //分组下无在权限内的攻略
                return raidersListVo;
            }
            //处理该公司攻略的解锁情况、得分情况，未解锁的攻略计算总共有几个公司解锁
            Set<Long> raidersIdIn = new HashSet<>();
            //攻略关联的所有功能点pointKey集合（可能不同攻略关联着相同的功能点），统一做一次查询即可
            Set<Integer> pointKeySet = new HashSet<>();
            for (RaidersEntity entity : list) {
                raidersIdIn.add(entity.getId());

                List<PointPojo> point = JsonHelperUtil.parseArray(JSONArray.toJSONString(entity.getPoint()), PointPojo.class);
                for (PointPojo pointPojo : point) {
                    pointKeySet.add(pointPojo.getPointKey());
                }
            }
            //pointKey-该功能点信息pojo（此pojo内只置入了功能点的name、icon和color）
            Map<Integer, PointPojo> keyPointMap = raidersHelp.handlePoint(pointKeySet);
            //标记是否需要对查询攻略公司关系时进行排序（私有分组内要根据推荐顺序查询）
            boolean recommendFlag = raidersHelp.checkRecommend(groupId);
            List<RaidersCorpEntity> raidersCorpList = raidersCorpModel.getRaidersCorpList(corpid, raidersIdIn, recommendFlag);
            //攻略id-攻略公司关系实体
            Map<Long, RaidersCorpEntity> corpRaidersMap = raidersCorpModel.corpRaidersMap(raidersCorpList, recommendFlag);

            Map<Long, RaidersVO> voMap;
            if (recommendFlag) {
                // 如果是推荐攻略，raidersHelp.getRaidersVoMap()方法的参数改为推荐攻略的顺序
                List<RaidersEntity> raidersRecommendList = new ArrayList<>();
                Map<Long, RaidersEntity> raidersMap = new LinkedHashMap<>();
                for (RaidersEntity raidersEntity : list) {
                    raidersMap.put(raidersEntity.getId(), raidersEntity);
                }
                for (RaidersCorpEntity entity : raidersCorpList) {
                    RaidersEntity raidersEntity = raidersMap.get(entity.getRaidersId());
                    raidersRecommendList.add(raidersEntity);
                }
                voMap = raidersHelp.getRaidersVoMap(raidersRecommendList, corpRaidersMap, keyPointMap);
            } else {
                //攻略id-攻略vo（先放入map，后续可能需要更新该攻略的point、lock、unLockTip等-未解锁时，需要算该攻略所有解锁的公司数）
                voMap = raidersHelp.getRaidersVoMap(list, corpRaidersMap, keyPointMap);
            }
            List<RaidersVO> raidersVoList = new ArrayList<>();
            if (recommendFlag) {
                //对攻略公司关系排序的，则按照推荐顺序封装攻略
                for (Map.Entry<Long, RaidersCorpEntity> entry : corpRaidersMap.entrySet()) {
                    RaidersVO raidersVO = voMap.get(entry.getKey());
                    if (raidersVO != null) {
                        raidersVoList.add(raidersVO);
                    }
                }
            } else {
                for (Map.Entry<Long, RaidersVO> entry : voMap.entrySet()) {
                    raidersVoList.add(entry.getValue());
                }
            }
            raidersListVo.setList(raidersVoList);
        } catch (Exception e) {
            LOG.error("获取攻略列表信息报错", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }

        return raidersListVo;
    }

    @Override
    public RaidersDetailVO detail(RaidersDetailDTO raidersDetailDTO) throws XbbException {
        RaidersDetailVO raidersDetailVO = new RaidersDetailVO();
        try {
            String corpid = raidersDetailDTO.getCorpid();
            //获取攻略实体，并过滤掉已删除、未发布的攻略
            RaidersEntity entity = raidersHelp.getRaidersEntity(corpid, raidersDetailDTO.getId(), I18nMessageUtil.getMessage(CommonConstant.VIEW));
            //攻略所在分组id
            Long groupId = entity.getGroupId();
            List<RaidersEntity> list = raidersHelp.getRaidersList4Filter(corpid, groupId, raidersDetailDTO.getLoginUser());
            if (list == null || list.size() == 0) {
                throw new XbbException(RaidersErrorCodeEnum.API_ERROR_800014, RaidersErrorCodeEnum.API_ERROR_800014.getMsg());
            }
            //获取攻略公司关系实体，如果不存在则初始化
            RaidersCorpEntity raidersCorpEntity = initRaidersCorpEntity(entity, corpid, raidersDetailDTO.getUserId());
            //处理解锁，如果未解锁，则不能查看详情
            checkLock(entity, list, raidersCorpEntity, corpid);

            BeanUtil.copyProperties(entity, raidersDetailVO);

            //处理step（要过滤掉未启用的步骤）
            List<StepInfoPojo> step = handleStep(entity, raidersCorpEntity);
            raidersDetailVO.setStep(step);
        } catch (XbbException e) {
            throw e;
        } catch (Exception e) {
            LOG.error("获取攻略详情信息报错", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }

        return raidersDetailVO;
    }

    @Override
    public RaidersOperationDetailVO operationDetail(RaidersOperationDetailDTO raidersOperationDetailDTO) throws XbbException {
        RaidersOperationDetailVO raidersOperationDetailVO = new RaidersOperationDetailVO();
        try {
            String corpid = raidersOperationDetailDTO.getCorpid();
            Long raidersId = raidersOperationDetailDTO.getId();
            /**********获取攻略实体，并过滤掉已删除、未发布的攻略**********/
            RaidersEntity entity = raidersHelp.getRaidersEntity(corpid, raidersId, I18nMessageUtil.getMessage(CommonConstant.VIEW));
            JSONObject operation = entity.getOperation();
            //步骤如果关闭，则无法操作
            if (raidersHelp.checkStepClose(operation)) {
                throw new XbbException(RaidersErrorCodeEnum.API_ERROR_800021, RaidersErrorCodeEnum.API_ERROR_800021.getMsg(), I18nMessageUtil.getMessage(CommonConstant.VIEW));
            }
            /**********获取攻略公司关系实体，如果不存在或锁定中，则不能操作**********/
            RaidersCorpEntity raidersCorpEntity = raidersHelp.getRaidersCorpEntity(corpid, raidersId);

            BeanUtil.copyProperties(entity, raidersOperationDetailVO);
            /**********title处理**********/
            JSONArray pointArr = entity.getPoint() == null ? new JSONArray() : entity.getPoint();
            int sizePoint = pointArr.size();
            String title = String.format(I18nMessageUtil.getMessage(RaidersConstant.OPERATION_DETAIL_TITLE), entity.getAvgTime(), sizePoint, entity.getName());
            raidersOperationDetailVO.setTitle(title);
            /**********停留时长计算**********/
            Integer seconds = raidersHelp.handleStaySeconds(raidersCorpEntity.getStartTime());
            raidersOperationDetailVO.setSeconds(seconds);
            if (seconds == 0) {
                //停留时长=0，则说明之前未开始，从现在开始
                Long now = DateUtil.getNow();
                raidersCorpEntity.setStartTime(now);
                raidersCorpEntity.setUpdateTime(now);
                raidersCorpModel.update(raidersCorpEntity);
            }
            /**********实操的score和scored处理**********/
            Integer score = operation.getIntValue("score");
            raidersOperationDetailVO.setScore(score);
            //步骤step值-完成情况pojo（主要是finish和score）
            Map<String, StepInfoPojo> stepMap = getStepMap(raidersCorpEntity);
            StepInfoPojo operationPojo = stepMap.get(RaidersStepEnum.OPERATION.getStep());
            if (operationPojo != null) {
                Integer scored = operationPojo.getScore();
                scored = scored == null ? Integer.valueOf(0) : scored;
                raidersOperationDetailVO.setScored(scored);
                //实操的finish处理
                Integer operationFinish = operationPojo.getFinish();
                operationFinish = operationFinish == null ? 0 : operationFinish;
                raidersOperationDetailVO.setFinish(operationFinish);
            }
            /**********实操的功能点point处理**********/
            //功能点pointKey-该功能点是否完成（0未完成 1已完成）
            Map<Integer, Integer> pointFinishMap = getPointFinishMap(raidersCorpEntity);
            List<PointPojo> point = JsonHelperUtil.parseArray(pointArr.toJSONString(), PointPojo.class);
            Set<Integer> pointKeySet = new HashSet<>();
            Set<String> permSet = raidersOperationDetailDTO.getLoginUser().getPermSet();
            for (PointPojo pointPojo : point) {
                Integer pointKey = pointPojo.getPointKey();
                //默认未完成
                Integer finish = pointFinishMap.getOrDefault(pointKey, 0);
                pointPojo.setFinish(finish);
                //处理权限
                disposePermission(pointPojo, permSet);
                pointKeySet.add(pointKey);
            }
            //功能点pointKey-该功能点选中的应用/菜单跳转需要的subBusinessType等信息
            Map<Integer, PointUrlBasePojo> urlBasePojoMap = raidersHelp.handlePointUrlBasePojo(corpid, pointKeySet);
            for (PointPojo pointPojo : point) {
                Integer pointKey = pointPojo.getPointKey();
                PointUrlBasePojo pointUrlBasePojo = urlBasePojoMap.get(pointKey);
                String pointUrl = raidersHelp.getPointUrl(pointUrlBasePojo);
                pointPojo.setPointUrl(pointUrl);
            }
            raidersOperationDetailVO.setPoint(point);
        } catch (XbbException e) {
            throw e;
        } catch (Exception e) {
            LOG.error("获取攻略详情-实操使用信息报错", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }

        return raidersOperationDetailVO;
    }

    /**
     * 移除某个分组的攻略
     *
     * @param raidersListVO
     * @throws XbbException
     * @author youli.chen
     * @date 19/9/24 024 13:48
     * @update 19/9/24 024 13:48
     * @version v1.0
     * @since v1.0
     */
    @Override
    public void removeRaider(RaidersListVO raidersListVO) throws XbbException {
        if(raidersListVO != null){
            List<RaidersVO> list = raidersListVO.getList();
            if(CollectionsUtil.isNotEmpty(list)){
                // 线上环境强制移除仓管角色(这里不需要国际化)
                list.removeIf(item -> Objects.equals(item.getName(), "仓管"));
            }
        }
    }

    /**
     * 获取攻略公司关系实体，如果不存在则初始化
     * @param entity 攻略实体
     * @param corpid 公司id
     * @param userId 登录员工userId
     * @return com.xbongbong.admin.domain.entity.RaidersCorpEntity
     * @throws XbbException
     * @author zcp
     * @date 19/9/29 029 14:58
     * @update 19/9/29 029 14:58
     * @since v1.0
     * @version v1.0
     */
    private RaidersCorpEntity initRaidersCorpEntity(RaidersEntity entity, String corpid, String userId) throws XbbException {
        Long raidersId = entity.getId();
        RaidersCorpEntity raidersCorpEntity = raidersCorpModel.getByRaidersId(raidersId, corpid);
        if (raidersCorpEntity != null) {
            if (Objects.equals(DelEnum.DELETE.getDel(), raidersCorpEntity.getDel())) {
                throw new XbbException(RaidersErrorCodeEnum.API_ERROR_800039);
            }
            return raidersCorpEntity;
        }
        //私有攻略，却没有攻略公司关联关系，则不能查看攻略
        if (Objects.equals(entity.getGroupId(), RaidersGroupRecommendEnum.RECOMMEND.getId())) {
            //如果报该错误，说明未给该公司推荐攻略，在运营中心，向该公司推荐即可
            throw new XbbException(RaidersErrorCodeEnum.API_ERROR_800017, RaidersErrorCodeEnum.API_ERROR_800017.getMsg());
        }
        //私有攻略需要设置sort，但是私有攻略的关联关系是在运营中心构建的
        long now = DateUtil.getNow();
        Integer recommend = RaidersConstant.NOT_RECOMMEND;
        if (Objects.equals(entity.getRange(), RaidersRangeEnum.OWN_PRIVATE.getCode())) {
            //私有攻略必须是推荐
            recommend = RaidersConstant.RECOMMEND;
        }
        raidersCorpEntity = new RaidersCorpEntity(corpid, userId, now, raidersId, recommend, 0, entity.getLock());
        raidersCorpModel.insert(raidersCorpEntity);
        return raidersCorpEntity;
    }

    /**
     * 处理公司攻略解锁
     * @param entity 攻略实体
     * @param list 该攻略所在分组内的攻略list
     * @param raidersCorpEntity 攻略公司关系实体
     * @param corpid 公司id
     * @return int
     * @throws XbbException
     * @author zcp
     * @date 19/9/29 029 15:17
     * @update 19/9/29 029 15:17
     * @since v1.0
     * @version v1.0
     */
    private int checkLock(RaidersEntity entity, List<RaidersEntity> list, RaidersCorpEntity raidersCorpEntity, String corpid) throws XbbException {
        Long raidersId = entity.getId();
        Integer index = null;
        Set<Long> raidersIdIn = new HashSet<>();
        Long lastId = null;
        //攻略id-攻略实体
        Map<Long, RaidersEntity> idRaidersMap = new HashMap<>(list.size());
        for (int i = 0; i < list.size(); i++) {
            RaidersEntity raidersEntity = list.get(i);
            Long id = raidersEntity.getId();
            if (index == null && Objects.equals(id, raidersId)) {
                //只有index还未被赋值时，且与raidersId相等时进来
                index = i;
                if (index != 0) {
                    lastId = list.get(index - 1).getId();
                }
            }
            raidersIdIn.add(id);
            idRaidersMap.put(id, raidersEntity);
        }
        //得到公司攻略关系，如果是推荐分组的，还需要按照推荐给该公司的顺序查看
        boolean recommendFlag = raidersHelp.checkRecommend(entity.getGroupId());
        List<RaidersCorpEntity> raidersCorpList = raidersCorpModel.getRaidersCorpList(corpid, raidersIdIn, recommendFlag);
        //攻略id-攻略公司关系实体
        Map<Long, RaidersCorpEntity> corpRaidersMap = raidersCorpModel.corpRaidersMap(raidersCorpList, recommendFlag);
        //推荐分组，index则按照推荐顺序获取
        if (recommendFlag) {
            index = null;
            for (int i = 0; i < raidersCorpList.size(); i++) {
                Long rid = raidersCorpList.get(i).getRaidersId();
                if (Objects.equals(rid, raidersId)) {
                    index = i;
                    if (index != 0) {
                        lastId = raidersCorpList.get(index - 1).getRaidersId();
                    }
                    break;
                }
            }
        }
        if (index == null) {
            //分组内无该攻略
            throw new XbbException(RaidersErrorCodeEnum.API_ERROR_800014, RaidersErrorCodeEnum.API_ERROR_800014.getMsg());
        }
        //上一步
        RaidersCorpEntity lastCorp = corpRaidersMap.get(lastId);
        RaidersEntity lastRaiders = idRaidersMap.get(lastId);
        int lock = raidersHelp.checkLock4Through(entity.getLock(), index, raidersCorpEntity, lastCorp, lastRaiders);
        if (Objects.equals(lock, RaidersLockEnum.FINISH_PRE_STEP.getCode())) {
            //未解锁
            throw new XbbException(RaidersErrorCodeEnum.API_ERROR_800015, RaidersErrorCodeEnum.API_ERROR_800015.getMsg());
        }
        //处理攻略是否完成
        boolean finishUpdate = raidersHelp.disposeRaidersFinish(entity, raidersCorpEntity, raidersCorpEntity.getStepScore());
        //可以解锁，但是关联关系未解锁，则更新解锁
        if (!Objects.equals(raidersCorpEntity.getLock(), lock) || finishUpdate) {
            raidersCorpEntity.setLock(lock);
            raidersCorpEntity.setUpdateTime(DateUtil.getNow());
            raidersCorpModel.update(raidersCorpEntity);
        }
        //处理finish状态

        return lock;
    }

    /**
     * 处理攻略内的步骤
     * @param entity 攻略实体
     * @param raidersCorpEntity 攻略公司关系，处理各个步骤的完成状态、得分值情况
     * @return java.util.List<com.xbongbong.admin.pojo.StepInfoPojo>
     * @author zcp
     * @date 19/9/29 029 15:54
     * @update 19/9/29 029 15:54
     * @since v1.0
     * @version v1.0
     */
    private List<StepInfoPojo> handleStep(RaidersEntity entity, RaidersCorpEntity raidersCorpEntity) {
        //步骤step值-完成情况pojo（主要是finish和score）
        Map<String, StepInfoPojo> stepMap = getStepMap(raidersCorpEntity);
        // TODO: 19/9/29 029 未加邀请步骤
        //步骤list
        List<JSONObject> stepArr = new ArrayList<>();
        //塞入instruction，处理finish和score（通过把raidersCorpEntity内各个步骤完成状态finish和完成分数score读出转换）
        handleStepInfo(stepArr, RaidersStepEnum.PREVIEW, entity.getPreview(), stepMap);
        handleStepInfo(stepArr, RaidersStepEnum.VIDEO, entity.getVideo(), stepMap);
        handleStepInfo(stepArr, RaidersStepEnum.OPERATION, entity.getOperation(), stepMap);
        handleStepInfo(stepArr, RaidersStepEnum.DOCUMENT, entity.getDocument(), stepMap);
        handleStepInfo(stepArr, RaidersStepEnum.MIRROR, entity.getMirror(), stepMap);
        List<StepInfoPojo> step = JsonHelperUtil.parseArray(JSONArray.toJSONString(stepArr), StepInfoPojo.class);
        return step;
    }

    /**
     * 得到各个步骤的完成情况map：构建步骤step和完成情况pojo的对应关系map
     * @param raidersCorpEntity
     * @return java.util.Map<java.lang.String,com.xbongbong.admin.pojo.StepInfoPojo>
     * @author zcp
     * @date 19/9/29 029 21:31
     * @update 19/9/29 029 21:31
     * @since v1.0
     * @version v1.0
     */
    private Map<String, StepInfoPojo> getStepMap(RaidersCorpEntity raidersCorpEntity) {
        JSONArray stepScoreArr = raidersCorpEntity.getStepScore();
        //步骤step值-完成情况pojo（主要是finish和score）
        Map<String, StepInfoPojo> stepMap = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        if (stepScoreArr != null) {
            //处理各个步骤的完成状态、得分值
            List<StepInfoPojo> stepScore = JsonHelperUtil.parseArray(JSONArray.toJSONString(stepScoreArr), StepInfoPojo.class);

            for (StepInfoPojo stepInfoPojo : stepScore) {
                stepMap.put(stepInfoPojo.getStep(), stepInfoPojo);
            }
        }
        return stepMap;
    }

    /**
     * 塞入step、instruction，处理finish和score
     * @param stepArr 步骤list，如果未启用则不塞入
     * @param stepEnum 步骤枚举
     * @param step 步骤
     * @param finishMap 步骤step值-完成情况pojo（主要是finish和score）
     * @author zcp
     * @date 19/9/29 029 19:13
     * @update 19/9/29 029 19:13
     * @since v1.0
     * @version v1.0
     */
    private void handleStepInfo(List<JSONObject> stepArr, RaidersStepEnum stepEnum, JSONObject step, Map<String, StepInfoPojo> finishMap) {
        if (raidersHelp.checkStepClose(step)) {
            //启用状态不为1，则不处理，直接返回
            return;
        }
        step.put("step", stepEnum.getStep());
        //塞入instruction
        step = RaidersStepEnum.addInstruction(step, stepEnum);
        // 放入title/button/summary
        step.put("title", step.getString("title"));
        step.put("summary", step.getString("summary"));
        step.put("button", step.getString("button"));
        if (Objects.equals(stepEnum, RaidersStepEnum.MIRROR)) {
            // 若是镜像，加上mirrorId 和 mirrorName
            step.put("mirrorId", step.getString("mirrorId"));
            step.put("mirrorName", step.getString("mirrorName"));
        }
        //处理finish和score
        StepInfoPojo stepInfoPojo = finishMap.getOrDefault(stepEnum.getStep(), new StepInfoPojo());
        step.put("finish", stepInfoPojo.getFinish());
        step.put("scored", stepInfoPojo.getScore());
        //塞入步骤list
        stepArr.add(step);
    }

    /**
     * 获取功能点pointKey和其对应完成情况map
     * @param raidersCorpEntity
     * @return java.util.Map<java.lang.Integer,java.lang.Integer>
     * @author zcp
     * @date 19/9/29 029 22:00
     * @update 19/9/29 029 22:00
     * @since v1.0
     * @version v1.0
     */
    private Map<Integer, Integer> getPointFinishMap(RaidersCorpEntity raidersCorpEntity) {
        String pointStateStr = raidersCorpEntity.getPointState() == null ? "" : raidersCorpEntity.getPointState().toJSONString();
        //功能点完成状态list
        List<PointPojo> pointState = JsonHelperUtil.parseArray(pointStateStr, PointPojo.class);
        //功能点pointKey-该功能点是否完成（0未完成 1已完成）
        Map<Integer, Integer> pointFinishMap = new HashMap<>(pointState.size());
        for (PointPojo pointPojo : pointState) {
            pointFinishMap.put(pointPojo.getPointKey(), pointPojo.getFinish());
        }
        return pointFinishMap;
    }

    /**
     * 判断权限
     *
     * @param pointPojo 功能点
     * @param permSet 权限
     * @author 徐俊杰
     * @date 2019/11/14 11:01
     * @since v1.0
     */
    private void disposePermission(PointPojo pointPojo, Set<String> permSet) {
        //该功能点对应的权限alias
        Integer pointKey = pointPojo.getPointKey();
        RaidersPointChildEnum pointKeyEnum = RaidersPointChildEnum.getByPointKey(pointKey);
        ProPermissionAliasEnum proPermissionAliasEnum = pointKeyEnum.getProPermissionAliasEnum();
        if (Objects.isNull(proPermissionAliasEnum)) {
            // 权限为null的表示不需要权限，直接置为1 (例如：首页)
            pointPojo.setPermission(RaidersConstant.PERMIT);
        } else {
            String permissionAlias = proPermissionAliasEnum.getAlias();
            //设置permission
            pointPojo.setPermission(RaidersConstant.NOT_PERMIT);
            if (permSet.contains(permissionAlias)) {
                pointPojo.setPermission(RaidersConstant.PERMIT);
            }
        }
    }
}
